package apps.web.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.hibernate.criterion.DetachedCriteria;
import org.springframework.web.servlet.ModelAndView;

import webframe.common.helper.ControllerHelper;
import webframe.common.helper.FormatTransformHelper;
import apps.web.controller.base.MyBaseCommandController;
import apps.web.model.Apply;

public class ApplySearchController extends MyBaseCommandController {

	@Override
	protected ModelAndView handleInner(HttpServletRequest request,
			HttpServletResponse response, Object command) {
		// delete apply
		if (request.getParameter("deleteApplyId") != null
				&& request.getParameter("deleteApplyId").trim().length() != 0) {
			getServiceContainer().getApplyBizService().deleteApply(
					ControllerHelper.extractId(request, "deleteApplyId"));
		}

		Apply capply = (Apply) command;
		DetachedCriteria criteria = DetachedCriteria.forClass(Apply.class);
		ControllerHelper.addEqualRestrictions(criteria, "id", capply.getId());
		ControllerHelper.addLikeRestrictions(criteria, "applyCode", capply
				.getApplyCode());
		ControllerHelper.addLikeRestrictions(criteria, "exhName", capply
				.getExhName());

		ControllerHelper.addBetweenRestrictions(criteria, "beginDate",
				FormatTransformHelper.string2Date(capply.getPreContactor()),
				FormatTransformHelper.string2Date(capply.getPreTelephone()));

		ControllerHelper.addEqualRestrictions(criteria, "entUserId", capply
				.getEntUserId());
		ControllerHelper.addEqualRestrictions(criteria, "applyFlag", capply
				.getApplyFlag());
		ControllerHelper.addEqualRestrictions(criteria, "archiveFlag", capply
				.getArchiveFlag());
		// //
		ControllerHelper.addEqualRestrictions(criteria, "delFlag", 0L);

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("page", ControllerHelper.queryPagination(request, criteria));
		map.put("capply", capply);
		return new ModelAndView("ApplyList.jsp", "map", map);
	}

}
